package com.hrm.util;


import java.security.MessageDigest;

/**
 * 获取字符串的md5摘要
 *
 * @author zekdot
 */
public class PasswordUtil {
    private static final String salt="orm";   //盐
    public static String getMd5(String value) {
        try {
            value=new StringBuffer().append(salt).append(value).toString(); //加盐做md5
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.update(value.getBytes("UTF8"));
            byte s[] = m.digest();
            StringBuilder resultBuilder = new StringBuilder();
            for (int i = 0; i < s.length; i++) {
                resultBuilder.append(Integer.toHexString((0x000000FF & s[i]) | 0xFFFFFF00).substring(6));
            }
            return resultBuilder.toString();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public static void main(String args[]){
        System.out.println(getMd5("123456"));
    }
}

